package ui;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import core.domain.IOUtil;
import core.domain.messages.NewFileMessage;

public class UIClient {

	private static Socket myPeer;
	public static Socket getSocket(){
		try{
		if(myPeer == null){
			myPeer = new Socket("localhost", 13467);
			return myPeer;
		}else {
			if(!myPeer.isConnected() || myPeer.isClosed()){
				myPeer = new Socket("localhost", 13467);
			}
			return myPeer;
		}}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public static void main(String[] args) throws UnknownHostException, IOException {
		//		13467
		NewFileMessage newFileMessage = new NewFileMessage("/Users/endre/Desktop/nyomorultak.txt");
		String newFileRequestString = IOUtil.getInstance(NewFileMessage.class).objectToString(newFileMessage);
		IOUtil.writeMessageToSocket(getSocket(), newFileRequestString, true);
		NewFileMessage newFileMessage2 = new NewFileMessage("/Users/endre/Desktop/prideAndPrejudice.txt");
		String newFileRequestString2 = IOUtil.getInstance(NewFileMessage.class).objectToString(newFileMessage2);
		IOUtil.writeMessageToSocket(getSocket(), newFileRequestString2, true);
		while (true) {
		}

	}
}
